package com.cait.dutyfree.action.converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

public class DatetimeConverter extends DefaultTypeConverter {
	private Date convertedDate;

	@Override
	public Object convertValue(Map<String, Object> context, Object value,
			Class toType) {
		System.out.println("Inside the datetimeconverter");
		if (toType == Date.class) {
			String datePattern = "dd-MM-yyyy";
			DateFormat df = new SimpleDateFormat(datePattern);
			df.setLenient(false);
			try {
				String[] dateString = (String[]) value;
				convertedDate = df.parse(dateString[0]);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return convertedDate;
	}

}
